package com.huang.springboot.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author yili_gi
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    /**
     * 加载Swagger Bean
     * Docket是Swagger的实例
     * @return
     */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("yili_gi")
                // 配置是否启用Swagger，填入一个boolean值
                .enable(true)
                .select()
                // RequestHandlerSelectors 配置请求处理选择器，用来配置选择哪些api
                .apis(RequestHandlerSelectors.basePackage("com.huang.springboot.controller"))
                // basePackage() 指定包下的接口都会被选择
                // any() 所有接口都选择
                // none() 所有接口都不选择
                // withMethodAnnotation() 选择方法上的注解作用的接口，参数是注解的类对象
                // withClassAnnotation() 选择类上的注解作用的接口，参数是注解的类对象
                .paths(PathSelectors.ant("/**"))
                // PathSelectors 路径选择器，指定选择的接口路径
                .build()
                ;
    }

    /**
     * 自定义Swagger ApiInfo
     * @return
     */
    private ApiInfo apiInfo(){
        Contact contact = new Contact("yili_gi","https://gitee.com/yili_gi","yili_gi@OutLook.com");
        return new ApiInfo("Api文档"
                ,"yili_gi"
                ,"1.0"
                ,"https://gitee.com/yili_gi/springboot_mybatis"
                ,contact
                ,"Apache 2.0",
                "https://www.apache.org/licenses/LICENSE-2.0"
                , new ArrayList<>()
                );
    }

}
